package com.zecan.blog.config;

import com.zecan.blog.utils.BlogConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbit mq 配置类
 * @ClassName RabbitMqConfig
 * @Description
 * @date 2022/11/24 18:02
 * @Version 1.0
 */

public class RabbitMqConfig {

    // 交换机注册
    @Bean
    public DirectExchange directExchange() {
        // param2  是否持久化, param3 是否自动删除
        return new DirectExchange(BlogConstant.RABBITMQ_EXCHANGE,true,true);
    }

    //聊天室队列注册
    @Bean
    public Queue ChatRoomQueue() {
        // param2  是否持久化,
        return new Queue(BlogConstant.RABBITMQ_CHATROOM_QUEUE,true);
    }

    // 发送邮件队列注册
    @Bean
    public  Queue SendEmailQueue() {
        return new Queue(BlogConstant.RABBITMQ_SEND_EMAIL_QUEUE,true);
    }

    @Bean
    public  Queue FollowQueue() {
        return new Queue(BlogConstant.RABBITMQ_FOLLOW_USER_QUEUE,true);
    }

    @Bean
    public  Queue UnFollowQueue() {
        return new Queue(BlogConstant.RABBITMQ_UNFOLLOW_USER_QUEUE,true);
    }
    // 通过路由将聊天室队列和交换机绑定
    @Bean
    public Binding ChatRoomBindEx() {
        return  BindingBuilder.bind(ChatRoomQueue()).to(directExchange()).with(BlogConstant.RABBITMQ_CHATROOM_ROUTING_KEY);

    }

    // 通过路由将发送路由队列和交换机绑定
    @Bean
    public Binding SendEmailBindEx(){
        return BindingBuilder.bind(SendEmailQueue()).to(directExchange()).with(BlogConstant.RABBITMQ_SEND_EMAIL_ROUTING_KEY);
    }
    @Bean
    public Binding FollowBindEx(){
        return BindingBuilder.bind(FollowQueue()).to(directExchange()).with(BlogConstant.RABBITMQ_FOLLOW_ROUTING_KEY);
    }
    @Bean
    public Binding UnFollowBindEx(){
        return BindingBuilder.bind(UnFollowQueue()).to(directExchange()).with(BlogConstant.RABBITMQ_UNFOLLOW_ROUTING_KEY);
    }

}
